<%@ page language="java"%>
<%@ page import="java.util.*,swimv2gm.bl.util.UserData"%>
<!DOCTYPE html>
<html>
<head>
<title>SWIMv2: Ricerca</title>
<link rel="stylesheet" type="text/css"
	href="/SWIMv2gm/shared/global.css" />
</head>
<body>
	<div id="header">
		<h1>SWIMv2</h1>
	</div>
	<%@include file="/shared/menu.jsp"%>
	<div id="content">
		<h1>Ricerca utenti</h1>
		<p>
			<em>Tutte le chiavi di ricerca sono opzionali.</em>
		</p>
		<%
			Map<String,String[]> params = (Map<String,String[]>)request.getAttribute("params");
		%>
		<form id="request" method="get" action="Search">
			<table>
				<tr>
					<td><label for="nome">Nome</label></td>
					<td><input name="nome"
						<%=(params != null && params.get("nome") != null) ? " value=\"" + params.get("nome")[0] + "\"" : ""%> /></td>
				</tr>
				<tr>
					<td><label for="cognome">Cognome</label></td>
					<td><input name="cognome"
						<%=(params != null && params.get("cognome") != null) ? " value=\"" + params.get("cognome")[0] + "\""
					: ""%> /></td>
				</tr>
				<tr>
					<td><label for="indirizzo">Indirizzo</label></td>
					<td><input name="indirizzo"
						<%=(params != null && params.get("indirizzo") != null) ? " value=\"" + params.get("indirizzo")[0]
					+ "\"" : ""%> /></td>
				</tr>
				<tr>
					<td><label for="bio">Altre informazioni</label></td>
					<td><input name="bio"
						<%=(params != null && params.get("bio") != null) ? " value=\"" + params.get("bio")[0] + "\"" : ""%> /></td>
				</tr>
				<tr>
					<td colspan="2" style="text-align: center;"><input
						type="radio" name="exclusive" value="true"
						<%=(params != null && params.get("exclusive") != null && Boolean.parseBoolean(params
					.get("exclusive")[0])) ? " checked=\"checked\"" : ""%> /><label
						for="true">Tutti i campi</label> <input type="radio"
						name="exclusive" value="false"
						<%=(params == null || params.get("exclusive") == null || !Boolean.parseBoolean(params
					.get("exclusive")[0])) ? " checked=\"checked\"" : ""%> /><label
						for="false">Almeno un campo</label></td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" value="Cerca" /></td>
				</tr>
			</table>
		</form>

		<%
			List<UserData> results = (List<UserData>)request.getAttribute("results");

			if (results != null) {
		%>
		<h1>Risultati ricerca</h1>
		<%
			if (results.size() == 0) {
		%>
		<p class="list">
			<em>Nessun risultato.</em>
		</p>
		<%
			}
				else {
		%>
		<p>
			Utenti trovati:
			<%=results.size()%>
		</p>
		<table class="list">
			<%
				for (UserData u:results) {
			%><tr>
				<td><a href="/SWIMv2gm/user/Profile?uid=<%=u.getId()%>"><%=u.getNome()%>
						<%=u.getCognome()%></a></td>
			</tr>
			<%
				}
			%>
		</table>
		<%
			}

			}
		%>
	</div>
</body>
</html>